<template>
	<view class="app-detail">
		<view class="detail-banner">
			<image :src="imgUrl('/static/img/imgs/order-img.png')" mode="aspectFit" />
			<view class="detail-back" @click="goBack">
				<uni-icons type="left" size="26"></uni-icons>
				<text class="banner-title">加项包详情</text>
			</view>
		</view>

		<view class="detail-content" v-if="currentPackage">
			<!--   <view class="orgn-detail">
                <text>加项包适用于瑞慈，美年，普惠三大品牌</text>
                <!-- <uni-icons type="right" size="20" color="#929292"></uni-icons> -->
			<!-- </view> -->

			<text class="detail-title">{{ currentPackage.title }}</text>
			<package-info :currentPackage="currentPackage" :expandedItems="expandedItems"/>
		</view>

		<view class="back-button" @click="goBack">返回</view>
	</view>
</template>
<script setup>
	import packageInfo from "../../../components/package-info/package-info.vue"
	import {
		ref
	} from 'vue'
	import {
		imgUrl
	} from "../../../utils/global";
	import {
		onLoad
	} from '@dcloudio/uni-app';
	import {
		nextTick
	} from 'vue';
	import {
		getCaseAddonByIdApi
	} from '@/api/case';

	const currentPackage = ref(null);

	// 展开/收起状态
	const expandedItems = ref([]);
	const expanded_any = ref(false)
	onLoad(async (options) => {
		await nextTick();

		if (typeof options.id === 'undefined') {
			uni.showToast({
				title: '获取加项包详情失败1',
				icon: 'none'
			});
			return;
		}

		try {
			const results = await getCaseAddonByIdApi({
				additionsid: options.id
			});
			currentPackage.value = results;
			results.items.forEach(item => {
				expandedItems.value.push(false)
			})
		} catch (error) {
			console.error('getCaseDetail error', error);
			uni.showToast({
				title: '获取加项包详情失败2',
				icon: 'none'
			});
		}
	});
	// 返回上一页
	const goBack = () => {
		uni.navigateBack();
	};
</script>
<style src="./style.scss" scoped />